package com.knowledge.review.designPatterns.structuralpattern.decoratorpattern.extenddemo;

// 炒饭类
public class FriedRice {
    String getDesc() {
        return "炒饭";
    }

    Integer getPrice() {
        return 5;
    }
}

// 炒饭加鸡蛋类
class FriedRiceAddEgg extends FriedRice {
    String getDesc() {
        return super.getDesc() + "+鸡蛋";
    }

    Integer getPrice() {
        return super.getPrice() + 2;
    }
}

// 炒饭加鸡蛋加火腿类
class FriedRiceAddEggAndHam extends FriedRiceAddEgg {
    String getDesc() {
        return super.getDesc() + "+火腿";
    }

    Integer getPrice() {
        return super.getPrice() + 3;
    }
}

class Test {
    // 测试方法
    public static void main(String[] args) {
        FriedRice friedRice = new FriedRice();
        System.out.println(friedRice.getDesc() + friedRice.getPrice() + "元");// 炒饭5元
        FriedRice friedRiceAddEgg = new FriedRiceAddEgg();
        System.out.println(friedRiceAddEgg.getDesc() + friedRiceAddEgg.getPrice() + "元"); // 炒饭+鸡蛋7元
        FriedRice friedRiceAddEggAndHam = new FriedRiceAddEggAndHam();
        System.out.println(friedRiceAddEggAndHam.getDesc() + friedRiceAddEggAndHam.getPrice() + "元");// 炒饭+鸡蛋+火腿10元
    }
}